package com.dis.producer;

import com.dis.entity.BaseData;
import com.lmax.disruptor.RingBuffer;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

@Slf4j
public class DataProducer extends Thread {

    private RingBuffer<BaseData>  ringBuffer;


    public DataProducer(RingBuffer<BaseData> ringBuffer, CountDownLatch countDownLatch) {
        this.ringBuffer = ringBuffer;
    }

    @Override
    public void run() {
        //todo
        long sequence = ringBuffer.next();
        try{
            while(true){
                BaseData baseData = ringBuffer.get(sequence);
                baseData.setDiscreteValue(true);
                log.info("发布了一条数据 {}",baseData );
            }
        }finally {
            ringBuffer.publish(sequence);
        }
    }
}
